/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Login.java
 *
 * Created on 27/03/2011, 09:22:16 PM
 */

package vista;

import java.util.Enumeration;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JRadioButton;
import manager.EmpleadoJpaController;
import manager.EvaluadorJpaController;
import org.jvnet.substance.SubstanceLookAndFeel;
import persistencia.Empleado;
import persistencia.Evaluador;

/**
 *
 * @author Armando Jr
 */
public class Login extends javax.swing.JFrame {

    /** Creates new form Login */
    public Login() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        campoTxtLogin = new javax.swing.JTextField();
        passTxtLogin = new javax.swing.JPasswordField();
        imgUsuarioLbl = new javax.swing.JLabel();
        imgPassLbl = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        btnValidarUsr = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Login");

        imgUsuarioLbl.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vista/usuario.jpg"))); // NOI18N
        imgUsuarioLbl.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        imgPassLbl.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vista/images.jpg"))); // NOI18N
        imgPassLbl.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jLabel3.setFont(new java.awt.Font("OCR A Extended", 1, 14));
        jLabel3.setText("Ingrese su Usuario y Contraseña");

        btnValidarUsr.setFont(new java.awt.Font("OCR A Extended", 1, 14));
        btnValidarUsr.setText("Aceptar");
        btnValidarUsr.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnValidarUsrActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED), "Ingresar como"));

        buttonGroup1.add(jRadioButton1);
        jRadioButton1.setText("Empleado");

        buttonGroup1.add(jRadioButton2);
        jRadioButton2.setText("Evaluador");
        jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(jRadioButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 77, Short.MAX_VALUE)
                .addComponent(jRadioButton2)
                .addGap(24, 24, 24))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jRadioButton2)
                    .addComponent(jRadioButton1))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(71, 71, 71)
                .addComponent(jLabel3)
                .addContainerGap(86, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(imgPassLbl)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(imgUsuarioLbl)
                        .addGap(29, 29, 29)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(campoTxtLogin)
                            .addComponent(passTxtLogin, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(44, 44, 44))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(136, Short.MAX_VALUE)
                .addComponent(btnValidarUsr)
                .addGap(137, 137, 137))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addGap(29, 29, 29)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(campoTxtLogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(imgUsuarioLbl))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(imgPassLbl))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(34, 34, 34)
                        .addComponent(passTxtLogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(31, 31, 31)
                .addComponent(btnValidarUsr)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnValidarUsrActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnValidarUsrActionPerformed
//este String es para colocar una opcion en el formulario login donde se puede escojer si
//entrar como evaluador o empleado.
//String perfil="Evaluador";
        String perfil="";
                Enumeration listaCargo = buttonGroup1.getElements();
                while(listaCargo.hasMoreElements()){
                    JRadioButton box = (JRadioButton)listaCargo.nextElement();
                    if(box.isSelected()){
                        perfil=box.getText();
                        System.out.println("Box "+box.getText()+" seleccionado");
                    }
                }

        if(perfil == "Empleado"){
        EmpleadoJpaController empleado = new EmpleadoJpaController();
        String pas = passTxtLogin.getText();
        Empleado em = empleado.buscarEmpleado(campoTxtLogin.getText(), pas);

                System.out.println(em.getIdEmpleado()
                + ", " + em.getNomEmpleado()
                + ", " + em.getApeEmpleado()
                + ", " + em.getIdDpto()
                + ", " + em.getCargo()
                + ", " + em.getDireccion()
                + ", " + em.getTelf()
                + ", " + em.getEmail()
                + ", " + em.getLogin()
                + ", " + em.getPass());
        }

        if(perfil == "Evaluador"){
        EvaluadorJpaController evaluador = new EvaluadorJpaController();
        String pas = passTxtLogin.getText();
        Evaluador ev = evaluador.buscarEvaluador(campoTxtLogin.getText(), pas);

                System.out.println(ev.getIdEvaluador()
                + ", " + ev.getNomEvaluador()
                + ", " + ev.getExperienciaLab()
                + ", " + ev.getEstudios()
                + ", " + ev.getEspecialidad()
                + ", " + ev.getIdProyMan()
                + ", " + ev.getEmail()
                + ", " + ev.getLogin()
                + ", " + ev.getPass());
        }

       
    }//GEN-LAST:event_btnValidarUsrActionPerformed

    private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jRadioButton2ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                    JFrame.setDefaultLookAndFeelDecorated(true);
                    //SubstanceLookAndFeel.setSkin("org.jvnet.substance.skin.OfficeSilver2007Skin");
                    SubstanceLookAndFeel.setSkin("org.jvnet.substance.skin.BusinessBlueSteelSkin");
                    //SubstanceLookAndFeel.setSkin("org.jvnet.substance.skin.BusinessBlackSteelSkin");
                    //SubstanceLookAndFeel.setSkin("org.jvnet.substance.skin.SaharaSkin");
                    //SubstanceLookAndFeel.setSkin("org.jvnet.substance.skin.MistAquaSkin");
                    // SubstanceLookAndFeel.setSkin("org.jvnet.substance.skin.NebulaSkin");
                    SubstanceLookAndFeel.setCurrentWatermark("org.jvnet.substance.watermark.SubstanceBinaryWatermark");
                   // SubstanceLookAndFeel.setCurrentTheme("org.jvnet.substance.theme.SubstanceAquaTheme");
                new Login().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnValidarUsr;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JTextField campoTxtLogin;
    private javax.swing.JLabel imgPassLbl;
    private javax.swing.JLabel imgUsuarioLbl;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JPasswordField passTxtLogin;
    // End of variables declaration//GEN-END:variables

}
